# encoding: utf-8

from IPython.display import display
from .stock import get_bar, get_symbols, get_symbol_score
from .chart import show
import re


def analysis(symbol, market=None, is_debug=1):
    items = []
    if market is not None:
        items.extend(get_symbols(market, 5000))

    symbol = symbol.upper()
    bars = get_bar(symbol)

    m = [x for x in items if x['symbol'] == symbol]
    extra = dict()
    if m:
        extra = m[0]

    info = get_symbol_score(symbol, bars, market=market, extra=extra, is_debug=is_debug)
    display(info)
    if re.match(r'(SH|SZ)+\d{6}', symbol):
        symbol = symbol[2:]
    show(symbol)
